package org.colafries.admin.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author colafries
 * @version v1.0
 * @ClassName MethodExecutionTimeAspect
 * @Description
 * @date Created in 2024/4/25
 **/
@Aspect
@Component
@Slf4j
public class MethodExecutionTimeAspect {
    @Around("@annotation(org.colafries.admin.annotation.LogExecutionTime)")
    public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long startTime = System.currentTimeMillis();

        Object proceed = joinPoint.proceed();

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;

        log.info(joinPoint.getSignature() + " 执行时间：" + duration + " 毫秒");

        return proceed;
    }
}
